/**
 * 
 */
package org.ko.core.domain.auth;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.ko.core.domain.support.BaseEntity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
 * UserRole
 * 
 * @author yangfuming
 * @date 2013-3-3
 */
@JsonIgnoreProperties( { "hibernateLazyInitializer", "handler" })
@Entity
@Table(name = "SYS_USER_ROLE")
public class UserRole extends BaseEntity {

	private static final long serialVersionUID = -6358444498996877889L;

	private User user;
	private Role role;

	public UserRole() {

	}

	public UserRole(Long userId, Long roleId) {
		this.user = new User(userId);
		this.role = new Role(roleId);
	}

	@JsonIgnore
	@ManyToOne
	@JoinColumn(name = "ROLE_ID", nullable = false)
	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}


	@JsonIgnore
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "USER_ID", nullable = false)
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
}
